package com.cavien.ser;

import java.util.List;

import com.cavien.ser.UserService;
import com.cavien.dao.UserDAO;
import com.cavien.entity.User;

public class UserServiceImpl implements UserService {
	private UserDAO userDAO;

	public boolean login(String username, String password) {
		User u = userDAO.queryUserByUsername(username);

		if (u == null) {
			return false;
		} else {
			if (u.getPassword().equals(password)) {
				userDAO.loginCount(u.getId());
				return true;
				
			} else {
				return false;
			}
		}
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	@Override
	public List<User> queryAll() {

		List <User>queryAll = userDAO.queryAll();

		return queryAll;
	}

	@Override
	public void userSaveOrUpdate(User user) {
		userDAO.userSaveOrUpdate(user);

	}

	@Override
	public User userEdit(Integer id) {
		User u = userDAO.queryUserById(id);
		return u;

	}

	@Override
	public void userDelete(User user) {
		userDAO.userDelete(user);
	}

}